<%@page contentType="text/html; charset=UTF-8" language="java"%>
<%@page import="com.travelsky.airchina.boarding.util.PageViewUtil"%>
<%@page import="com.travelsky.airchina.boarding.util.PageUtil"%>
<%@page import="com.travelsky.airchina.boarding.common.ConstType"%>
<%@page import="com.travelsky.airchina.boarding.dto.NewsColumnView"%>
<%@page import="com.travelsky.airchina.boarding.dto.NewsSearchCondition"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="java.util.HashMap"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>管理中心 - 新闻列表 </title>
	<meta name="robots" content="noindex, nofollow"/>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link href="${ctx}/css/system/general.css" rel="stylesheet" type="text/css" />
	<link href="${ctx}/css/system/main.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${ctx}/js/checkFrameSet.js"></script>
	<script language="javascript" type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery-1.4.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/json.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/operationTip.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery-select.js"></script>
	<script language="JavaScript">
	    function updateStatus(newsId,newsStatusCode){
			$.getJSON("${ctx}/system/news/updatestatus", { id: newsId,status:newsStatusCode }, function(data) {
		  	    if(data.updateFlag==true){
		  	       if(newsStatusCode==${NEWS_STATUS_AUDIT_PUBLISH}){
		  	          $("#status"+newsId).text("审核发布");
		  	          $("#statusOperation"+newsId).html("<a href=\"javascript:void(0);\" onclick=\"javascript:updateStatus("+newsId+",${NEWS_STATUS_AUDIT_NOT_PASS});\" title=\"审核不通过\">审核不通过</a>");
		  	       }else if(newsStatusCode==${NEWS_STATUS_AUDIT_NOT_PASS}){
		  	          $("#status"+newsId).text("审核不通过");
		  	          $("#statusOperation"+newsId).html("<a href=\"javascript:void(0);\" onclick=\"javascript:updateStatus("+newsId+",${NEWS_STATUS_AUDIT_PUBLISH});\" title=\"审核通过\">审核通过</a>");
		  	       }else if(newsStatusCode==${NEWS_STATUS_AUDIT_ARCHIVE}){
		  	          $("#status"+newsId).text("归档");
		  	          $("#statusOperation"+newsId).html("<a href=\"javascript:void(0);\" onclick=\"javascript:updateStatus("+newsId+",${NEWS_STATUS_AUDIT_PUBLISH});\" title=\"审核通过\">审核通过</a> ");
		  	       }
		  	       $("#statusOperationTip"+newsId).text("操作成功");
		  	       $("#statusOperationTip"+newsId).fadeIn("normal",function(){$("#statusOperationTip"+newsId).fadeOut(2000)});
		  	    }else{
		  	       $("#statusOperationTip"+newsId).text("操作失败");
		  	       $("#statusOperationTip"+newsId).fadeIn("normal",function(){$("#statusOperationTip"+newsId).fadeOut(2000)});
		  	    }
			});
	    }
	    function onchangeColumn(columnSelect){
	       var selectId = columnSelect.id;
	       var nextSelectId = parseInt(selectId.substring(8))+1;
	       if(columnSelect.value!=""){
		       $.getJSON("${ctx}/system/news/findchildrencolumn",{pId:columnSelect.value},function(data){
		         if(data!=null && data.length>0){
		            $("#"+selectId).nextAll().remove();
		            $("#"+selectId).after("&nbsp;&nbsp;<select name='columnId"+nextSelectId+"' id='columnId"+nextSelectId+"' onchange='javascript:onchangeColumn(this);'></select>");
		            $("#columnId"+nextSelectId).addOption("请选择","");
		            for(var i=0;i<data.length;i++){
		                $("#columnId"+nextSelectId).addOption(data[i].name,data[i].id);
		            }
		         }else{
		            $("#"+selectId).nextAll().remove();
		         }
		       });
	       }else{
	           $("#"+selectId).nextAll().remove();
	       }
	    }
	</script>
</head>
<body>
<h1>
<c:if test="${USER_OPERATION_URIS_MAP['/system/news']!=null}">
<span class="action-span"><a href="${ctx}/system/news">新建新闻</a></span>
</c:if>
<span class="action-span1"><a href="#">管理中心</a>  - 新闻列表 </span>
<div style="clear:both"></div>
</h1>
<%
String operationFlag = (String)request.getAttribute("operationFlag");
if(operationFlag!=null){
   if("t".equals(operationFlag)){
%>
  <ul class="actionMessage">
    <li>操作成功
    </li>
  </ul>
<%
   }else if("f".equals(operationFlag)){
%>
  <ul class="errorMessage">
    <li>操作失败
    </li>
  </ul>
<%
   }
}
%>
<form method="post" action="${ctx}/system/news/list" id="listForm" name="listForm">
<table width="100%">
   <tr>
    <td>新闻栏目</td>
    <td colspan="3">
    <select id="columnId0" name="columnId0" onchange="javascript:onchangeColumn(this);">
       <option value="">请选择栏目</option>
     <c:if test="${userAuthorityRootColumns!=null}">
       <c:forEach items="${userAuthorityRootColumns}" var="varTemp">
         <c:choose>
           <c:when test="${selectedRootColumnId==varTemp.id}">
       <option value="${varTemp.id}" selected="selected">${varTemp.name}</option>
           </c:when>
           <c:otherwise>
       <option value="${varTemp.id}">${varTemp.name}</option>
           </c:otherwise>
         </c:choose>
       </c:forEach>
     </c:if>
    </select>
    <%
    @SuppressWarnings("unchecked")
    Map<Long,List<NewsColumnView>> map = (Map<Long,List<NewsColumnView>>)request.getAttribute("userSelectNewsColumnMap");
    List<Long> selectNewsColumnIds = null;
    NewsSearchCondition newsSearchCondition = (NewsSearchCondition)request.getAttribute("newsSearchCondition");
    if(newsSearchCondition!=null){
    	selectNewsColumnIds = newsSearchCondition.getColumnIds();
    }
    if(selectNewsColumnIds!=null && selectNewsColumnIds.size()>0){
    	if(map==null){
    		map = new HashMap<Long,List<NewsColumnView>>();
    	}
    	for(int i=0;i<selectNewsColumnIds.size();i++){
    		List<NewsColumnView> list = map.get(selectNewsColumnIds.get(i));
    		if(list!=null && list.size()>0){
    			%>
    &nbsp;&nbsp;<select name="columnId<%=i+1%>" id="columnId<%=i+1%>" onchange="javascript:onchangeColumn(this);">
        <option value="">请选择</option>
               <%
               for(NewsColumnView temp:list){
            	   if(selectNewsColumnIds.contains(temp.getId())){
                	   %>
                       <option value="<%=temp.getId()%>" selected="selected"><%=temp.getName()%></option>      	   
                       <%
            	   }else{
                	   %>
                       <option value="<%=temp.getId()%>"><%=temp.getName()%></option>      	   
                       <%
            	   }
               }
               %>
    </select>
    		    <%
    		}
    	}
    }
    %>
    </td>
   </tr>
   <tr>
    <td>新闻标题</td>
    <td><input type="text" id="title" name="title" value="${newsSearchCondition.title}"/></td>
    <td>创建时间</td>
    <td><input class="Wdate" size="15" value="<fmt:formatDate value='${newsSearchCondition.beginTime}' type='date'/>" name="beginTime" id="beginTime" type="text" onclick="javascript:WdatePicker({isShowWeek:true});"/> 至 <input class="Wdate" id="endTime" name="endTime" type="text" value="<fmt:formatDate value='${newsSearchCondition.endTime}' type='date'/>" size="15" onclick="javascript:WdatePicker({isShowWeek:true});"/></td>
   </tr>
   <tr>
    <td>新闻状态</td>
    <td>
    <select name="newStatus" id="newStatus">
       <c:choose>
         <c:when test="${newsSearchCondition.newStatus==NEWS_STATUS_NO_AUDIT}">
       <option value="">请选择</option>
       <option value="${NEWS_STATUS_NO_AUDIT}" selected="selected">未审核</option>
       <option value="${NEWS_STATUS_AUDIT_PUBLISH}">审核发布</option>
       <option value="${NEWS_STATUS_AUDIT_NOT_PASS}">审核不通过</option>
         </c:when>
         <c:when test="${newsSearchCondition.newStatus==NEWS_STATUS_AUDIT_PUBLISH}">
       <option value="">请选择</option>
       <option value="${NEWS_STATUS_NO_AUDIT}">未审核</option>
       <option value="${NEWS_STATUS_AUDIT_PUBLISH}" selected="selected">审核发布</option>
       <option value="${NEWS_STATUS_AUDIT_NOT_PASS}">审核不通过</option>
         </c:when>
         <c:when test="${newsSearchCondition.newStatus==NEWS_STATUS_AUDIT_NOT_PASS}">
       <option value="">请选择</option>
       <option value="${NEWS_STATUS_NO_AUDIT}">未审核</option>
       <option value="${NEWS_STATUS_AUDIT_PUBLISH}">审核发布</option>
       <option value="${NEWS_STATUS_AUDIT_NOT_PASS}" selected="selected">审核不通过</option>
         </c:when>
         <c:otherwise>
       <option value="">请选择</option>
       <option value="${NEWS_STATUS_NO_AUDIT}">未审核</option>
       <option value="${NEWS_STATUS_AUDIT_PUBLISH}">审核发布</option>
       <option value="${NEWS_STATUS_AUDIT_NOT_PASS}">审核不通过</option>
         </c:otherwise>
       </c:choose>
    </select>
    </td>
    <td>新闻类型</td>
    <td>
    <select name="columnType" id="columnType">
       <c:choose>
         <c:when test="${newsSearchCondition.columnType==COLUMN_TYPE_NEWS}">
       <option value="">请选择</option>
       <option value="${COLUMN_TYPE_NEWS}" selected="selected">普通新闻</option>
       <option value="${COLUMN_TYPE_IMAGE_NEWS}">图文新闻</option>
       <option value="${COLUMN_TYPE_VIDEO_NEWS}">视频新闻</option>
         </c:when>
         <c:when test="${newsSearchCondition.columnType==COLUMN_TYPE_IMAGE_NEWS}">
       <option value="">请选择</option>
       <option value="${COLUMN_TYPE_NEWS}">普通新闻</option>
       <option value="${COLUMN_TYPE_IMAGE_NEWS}" selected="selected">图文新闻</option>
       <option value="${COLUMN_TYPE_VIDEO_NEWS}">视频新闻</option>
         </c:when>
         <c:when test="${newsSearchCondition.columnType==COLUMN_TYPE_VIDEO_NEWS}">
       <option value="">请选择</option>
       <option value="${COLUMN_TYPE_NEWS}">普通新闻</option>
       <option value="${COLUMN_TYPE_IMAGE_NEWS}">图文新闻</option>
       <option value="${COLUMN_TYPE_VIDEO_NEWS}" selected="selected">视频新闻</option>
         </c:when>
         <c:otherwise>
       <option value="">请选择</option>
       <option value="${COLUMN_TYPE_NEWS}">普通新闻</option>
       <option value="${COLUMN_TYPE_IMAGE_NEWS}">图文新闻</option>
       <option value="${COLUMN_TYPE_VIDEO_NEWS}">视频新闻</option>
         </c:otherwise>
       </c:choose>
    </select>
    &nbsp;&nbsp;<input type="submit" value="查询"/>
    </td>
   </tr>
</table>
<div class="list-div" id="listDiv">
<table width="100%" cellpadding="3" cellspacing="1" id="listTable">
  <tr>
    <th>序号</th>
    <th>新闻标题</th>
    <th>所在栏目</th>
    <th>创建时间</th>
    <th>状态</th>
    <th>操作</th>
  </tr>
  <c:forEach items="${list}" var="itemTemp" varStatus="statusTemp">
  <tr>
    <td class="first-cell">
    ${statusTemp.index+1}
    </td>
    <td class="first-cell">
    <c:choose>
       <c:when test="${fn:length(itemTemp.title)>25}">
    <span title="${itemTemp.title}">${fn:substring(itemTemp.title,0,24)}...</span>
       </c:when>
       <c:otherwise>
    ${itemTemp.title}
       </c:otherwise>
    </c:choose>
    </td>
    <td align="center">${itemTemp.columnName}</td>
    <td align="center"><fmt:formatDate value="${itemTemp.createdTime}" type="date"/></td>
    <td align="center">
    <div class="statusDiv" id="statusDiv${itemTemp.id}">
	    <span id="status${itemTemp.id}">
	    <c:choose>
	      <c:when test="${itemTemp.status==NEWS_STATUS_NO_AUDIT}">未审核</c:when>
	      <c:when test="${itemTemp.status==NEWS_STATUS_AUDIT_PUBLISH}">审核发布</c:when>
	      <c:when test="${itemTemp.status==NEWS_STATUS_AUDIT_NOT_PASS}">审核不通过</c:when>
	      <c:when test="${itemTemp.status==NEWS_STATUS_AUDIT_ARCHIVE}">已归档</c:when>
	      <c:otherwise>未知状态</c:otherwise>
	    </c:choose>
	    </span>
	    <div class="statusOperationTip" id="statusOperationTip${itemTemp.id}"></div>
    </div>
    </td>
    <td align="center">
      <a href="${ctx}<%=ConstType.NEWS_HTML_PATH%>${itemTemp.htmlUrl}" target="_blank" title="预览">预览</a>
      <c:if test="${USER_OPERATION_URIS_MAP['/system/news/view']!=null}"> | <a href="${ctx}/system/news/view/${itemTemp.id}" title="查看">查看</a></c:if>
      <c:if test="${USER_OPERATION_URIS_MAP['/system/news/update']!=null}"> | <a href="${ctx}/system/news/update/${itemTemp.id}" title="编辑">编辑</a></c:if>
      <c:if test="${USER_OPERATION_URIS_MAP['/system/news/delete']!=null}"> | <a href="${ctx}/system/news/delete/${itemTemp.id}" title="编辑">删除</a></c:if>
      <c:if test="${USER_OPERATION_URIS_MAP['/system/news/updatestatus']!=null}">
      <span id="statusOperation${itemTemp.id}">
	    <c:choose>
	      <c:when test="${itemTemp.status==NEWS_STATUS_NO_AUDIT}">
       | <a href="javascript:void(0);" onclick="javascript:updateStatus('${itemTemp.id}','${NEWS_STATUS_AUDIT_PUBLISH}');" title="审核发布">审核发布</a>
	      </c:when>
	      <c:when test="${itemTemp.status==NEWS_STATUS_AUDIT_PUBLISH}">
       | <a href="javascript:void(0);" onclick="javascript:updateStatus('${itemTemp.id}','${NEWS_STATUS_AUDIT_NOT_PASS}');" title="审核不通过">审核不通过</a>
	      </c:when>
	      <c:when test="${itemTemp.status==NEWS_STATUS_AUDIT_NOT_PASS}">
       | <a href="javascript:void(0);" onclick="javascript:updateStatus('${itemTemp.id}','${NEWS_STATUS_AUDIT_PUBLISH}');" title="审核通过">审核通过</a>
	      </c:when>
	      <c:when test="${itemTemp.status==NEWS_STATUS_AUDIT_ARCHIVE}">
       | <a href="javascript:void(0);" onclick="javascript:updateStatus('${itemTemp.id}','${NEWS_STATUS_AUDIT_PUBLISH}');" title="审核发布">审核发布</a>
	      </c:when>
	      <c:otherwise>
       | <a href="javascript:void(0);" onclick="javascript:updateStatus('${itemTemp.id}','${NEWS_STATUS_AUDIT_PUBLISH}');" title="审核发布">审核发布</a> |
      <a href="javascript:void(0);" onclick="javascript:updateStatus('${itemTemp.id}','${NEWS_STATUS_AUDIT_NOT_PASS}');" title="审核不通过">审核不通过</a>
	      </c:otherwise>
	    </c:choose>
	    </span>
	    </c:if>
    </td>
  </tr>
  </c:forEach>
  </table>
</div>
  <div class="page-navigation">
  <%
  PageUtil pageUtil = (PageUtil)request.getAttribute("pageUtil");
  PageViewUtil.printPage(out, pageUtil, "100%","listForm",request.getContextPath()+"/system/news/list","_self",false);
  %>
  </div>
</form>
</body>
</html>